package com.cskaoyan.controller;

import com.cskaoyan.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author stone
 * @date 2022/04/29 10:20
 */
@Controller
public class AccountController {

    @Autowired
    AccountService accountService;

    //发送请求localhost:8080/transfer?fromId=1&destId=2&money=1000
    //在该Handler方法中完成由1给2转1000元的业务,要求包含事务
    // (参数我已经帮大家接收到了，大家只处理转账业务)
    @RequestMapping("transfer")
    @ResponseBody
    public String transfer(HttpServletRequest request) {
        Integer fromId = Integer.valueOf(request.getParameter("fromId"));
        Integer destId = Integer.valueOf(request.getParameter("destId"));
        Integer money = Integer.valueOf(request.getParameter("money"));
        accountService.transfer(fromId, destId, money);
        return "ok";
    }
}
